package cn.scw.project.goods.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.goods.domain.netework.bean.GOrderCommodityListReq;
import cn.scw.project.goods.domain.vo.GOrderCommodityVo;
import cn.scw.project.goods.service.IGOrderCommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单商品Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "订单商品")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/goods/order/commodity")
public class GOrderCommodityController extends BaseController {
    @Autowired
    private IGOrderCommodityService gOrderCommodityService;


    @ApiOperation("查询订单商品列表")
    //@PreAuthorize("@ss.hasPermi('goods:commodity:list')")
    @GetMapping("/list")
    public TableDataInfo list(GOrderCommodityListReq req) {
        startPage();
        List<GOrderCommodityVo> list = gOrderCommodityService.selectGOrderCommodityList(req);
        return getDataTable(list);
    }

    @ApiOperation("查询订单的商品列表")
    @GetMapping("/order/list/{orderId}")
    private TableDataInfo listByOrder(@PathVariable @Param("订单id") Long orderId) {
        startPage();
        List<GOrderCommodityVo> list = gOrderCommodityService.selectGOrderCommodityVoListByOrder(orderId);
        return getDataTable(list);
    }

    @ApiOperation("获取订单商品详细信息")
    //@PreAuthorize("@ss.hasPermi('goods:commodity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gOrderCommodityService.selectGOrderCommodityVoById(id));
    }
}
